//
//  Payload.swift
//  SecretChat
//
//  Created by TimTiger on 16/6/27.
//  Copyright © 2016年 TimTiger. All rights reserved.
//

import UIKit
import Foundation

public class Payload: NSObject {
    public lazy var deviceTokens: [String] = [String]()
    public lazy var aps: [String: AnyObject] = ["aps": ["alert": "message from some one","badge": NSNumber(integer: 1),"sound": "default"]]
    public var messageInfo: [String: AnyObject]?
    
    //MARK: - Public 
    public func data()->NSData? {
        let dataString: String? = "{\"aps\":{\"alert\":\"message from some one\",\"badge\":1,\"sound\":\"default\"},\"message\":\"hello\"}"//self.preparePayloadString()
        if dataString == nil {
            return nil
        }
        return dataString?.dataUsingEncoding(NSUTF8StringEncoding)
    }
    
    //MARK: - Private
    private func preparePayloadString()->String? {
        var payloadDictionary = [String: AnyObject]()
        payloadDictionary.addOtherDictionary(self.aps)
        payloadDictionary.addOtherDictionary(self.messageInfo)
        let result = NSJSONSerialization.jsonStringWithObject(payloadDictionary)
        return result
    }
}
